//一段时间内只执行一次
function throttle(func, wait) {
  let lastTime = 0;

  return function (...args) {
    const now = new Date().getTime();
    if (now - lastTime >= wait) {
      func.apply(this, args);
      lastTime = now;  // 更新上次执行时间
    }
  };
}

// 定义自定义指令
export const vThrottle = {
  mounted(el, binding) {
    const limit = binding.arg || 300; // 默认时间间隔为 300 毫秒
    const callback = binding.value;
    el.addEventListener('click', throttle(callback, limit));
  },
};